<template>
  <CommonPanel title="实时告警" :loading="loading">
    <div class="main-box">
      <div class="people_card" v-for="(item, index) in tableData" :key="index">
        <div class="image" :style="{ objectFit: 'cover',height:'50%',backgroundImage:`url(${apiKey + item.picUri})`}" v-on:click="openImageInNewPage(apiKey + item.picUri)">
          <div class="back">{{ item.personName }}</div>
          <img  alt="" style="width: 100%" />
        </div>
        <div class="title">{{ item.eventName }}</div>
        <div class="area">{{ item.doorName }}</div>
        <div class="title">{{ item.eventTime }}</div>
      </div>
    </div>
  </CommonPanel>
</template>

<script setup>
import man_1 from "@/assets/man_1.png";
import { onMounted, reactive, ref, onUnmounted } from "vue";
import { eventRcvs } from "@/api/security-board";
function openImageInNewPage(imageUrl) {
  window.open(imageUrl,'_black')
       }
let apiKey = "http://192.168.100.1";

onMounted(() => {
  // 在这里访问环境变量
  apiKey = "http://192.168.100.1";
});
const tableData = ref([]);
let timer;
onMounted(() => {
  getDataList();
  timer = setInterval(getDataList, 10000);
});
onUnmounted(() => {
  clearInterval(timer);
});
function getDataList() {
  eventRcvs().then((res) => {
    if (res.code === 1) {
      tableData.value = res.data.length < 4 ? res.data : res.data.slice(0, 4);
    }
  });
}
</script>
<style lang="scss" scoped>
.main-box {
  display: flex;
  box-sizing: border-box;
  padding: 10px 6px;
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-column-gap: 30px;

  &>div {
    background: url("../../../assets/image/people.png") no-repeat center 0px;
    background-size: cover;
  }

  .image {
    position: relative;
    background-size: contain;
     background-repeat: no-repeat; 
     background-position: center;

    .back {
      position: absolute;
      bottom: 0;
      left: 0;
      background: rgba($color: #000000, $alpha: 0.2);
      color: white;
      font-size: 16px;
      width: 100%;
      padding: 10px 20px;
    }
  }

  .people_card {
    color: white;
    font-size: 14px;
    padding: 12px 12px;

    .title {
      opacity: 0.5;
      margin-top: 10px;
    }

    .area {
      margin-top: 20px;
      font-size: 16px;
    }
  }
}
</style>
